package com.zls.service.impl;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.zls.mapper.TTaskMapper;
import com.zls.page.PageResult;
import com.zls.page.QueryPageBean;
import com.zls.pojo.TFarm;
import com.zls.pojo.TTask;
import com.zls.service.TTaskService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.Date;
import java.util.List;
@Service
public class TTaskServiceImpl extends ServiceImpl<TTaskMapper, TTask> implements TTaskService {
    @Autowired
    private TTaskMapper tTaskMapper;
    @Override
    public PageResult findPage(QueryPageBean queryPageBean) {
        PageResult pageResult = new PageResult();
        Integer currentPage = queryPageBean.getCurrentPage();//当前页
        Integer pageSize = queryPageBean.getPageSize();//每页大小
        String queryString = queryPageBean.getQueryString();//查询条件
        //total总记录数
        List<TTask> page = tTaskMapper.findPage((currentPage - 1) * pageSize, pageSize,queryString);
        //rows  当前页的数据
        Long count = tTaskMapper.count(queryString);
        pageResult.setRows(page);
        pageResult.setTotal(count);
        return pageResult;
    }

    @Override
    @Transactional
    public int addTTask(TTask tTask) {
        tTask.setCreateDate(new Date());
        return tTaskMapper.addTTask(tTask);
    }

    @Override
    @Transactional
    public int editTTask(TTask tTask) {
        tTask.setState(1);
        int i = tTaskMapper.updateById(tTask);
        return i;
    }

    @Override
    @Transactional
    public int editTTasks(TTask tTask) {
        tTask.setFinishDate(new Date());
        int i = tTaskMapper.updateById(tTask);
        return i;
    }

    @Override
    public int submit(TTask tTask) {
        tTask.setState(2);
        int i = tTaskMapper.updateById(tTask);
        return i;
    }
}
